const Mock = require("mockjs");
const Random = Mock.Random;
const Dictionary = {
  servicesPack: ["标准服务包A", "人行A会员", "标准服务包C", "标准服务包B", "Z会员"],
  services: ["就医代办", "智能体质辨识", "视屏问诊", "挂号代办"],
  companyName: ["国贸医疗大数据公司", "人行公司", "厦大小小科技", "巨大农业"],
  source: ["惠厦保", "鹭AI保"],
  expirationDate: ["1年", "6个月", "30天"],
  status: ["启用", "禁用"],
  serviceStatusName: ["进行中", "未开始", "已完成"]
};

// 会员用户列表
const memberUserList = function () {
  const list = [];
  for (let i = 0; i < 20; i++) {
    const obj = {
      "id": Random.id(),
      "userName": Random.string(5),
      "servicesPack": [],
      "status": Random.boolean(),
      "realName": Random.cname(),
      "phone": "12345678901",
      "companyName": Random.pick(Dictionary.companyName),
      "source": Random.pick(Dictionary.source),
      "recentConsumption": Random.datetime("yyyy-MM-dd"),
      "expirationDate": Random.pick(Dictionary.expirationDate),
      "becomeDate": Random.datetime("yyyy-MM"),
      "startDate": Random.datetime("yyyy-MM"),
      "endDate": Random.datetime("yyyy-MM")
    };

    const servicesPackArray = [];
    const servicesPackLength = Math.floor(Math.random() * Dictionary.servicesPack.length) + 1;
    for (let m = 0; m < servicesPackLength; m++) {
      const servicesPackItem = {
        servicePackId: Random.id(),
        servicePackName: Mock.Random.pick(Dictionary.servicesPack),
        serviceItems: []
      };
      const servicesList = [];
      for (let n = 0; n < Dictionary.services.length; n++) {
        servicesList.push({
          "serviceItemId": Random.id(),
          "serviceItemName": Random.pick(Dictionary.services),
          "useLimit": Random.integer(3, 10),
          "available": Random.integer(3, 10)
        });
        servicesPackItem.serviceItems.push(servicesList);
      }
      servicesPackArray.push(servicesPackItem);
    }
    obj.servicesPack = servicesPackArray;

    list.push(obj);
  }
  return list;
};
Mock.mock("/mock/getMemberList", memberUserList);

// 会员详情列表
const memberDetail = function () {
  const list = [];
  for (let i = 0; i < 5; i++) {
    const obj = {
      "servicesPackName": Random.pick(Dictionary.servicesPack),
      "statusName": Random.pick(Dictionary.status),
      "useBy": Random.pick(Dictionary.companyName),
      "becomeDate" : Random.datetime("yyyy-MM-dd HH:mm:ss"),
      "startDate": Random.datetime("yyyy-MM-dd"),
      "endDate": Random.datetime("yyyy-MM-dd"),
      "expirationDate": Random.pick(Dictionary.expirationDate),
      "children": []
    };
    for (let m = 0; m < 3; m++) {
      const child = {
        "servicesPackName": obj.servicesPackName,
        "serviceName": Random.pick(Dictionary.services),
        "serviceStatus": Random.pick(Dictionary.serviceStatusName),
        "limited": Random.integer(3, 10),
        "used": Random.integer(3, 10),
        "time": Random.datetime("yyyy-MM-dd HH:mm:ss")
      };
      obj.children.push(child);
    }
    list.push(obj);
  }
  return list;
};
Mock.mock("/mock/getMemberDetailList", memberDetail);
